class Solution(object):
    def mostCompetitive(self, nums, k):
        st = []
        n = len(nums)
        for index, num in enumerate(nums):
            while st and num < st[-1] and len(st) - 1 + n - index >= k:
                st.pop()
            if len(st) < k:
                st.append(num)
        return st


data = Solution()
nums = [3, 5, 2, 6]
k = 2
print(data.mostCompetitive(nums, k))
